package com.hixtrip.sample.app.strategy;

import com.hixtrip.sample.app.api.OrderService;
import com.hixtrip.sample.app.convertor.OrderConvertor;
import com.hixtrip.sample.client.common.R;
import com.hixtrip.sample.client.order.dto.CommandPayDTO;
import com.hixtrip.sample.domain.inventory.repository.InventoryRepository;
import com.hixtrip.sample.domain.order.OrderDomainService;
import com.hixtrip.sample.domain.order.repository.OrderRepository;
import com.hixtrip.sample.domain.pay.model.CommandPay;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class PayStrategy {



    @AllArgsConstructor
    private enum Strategy {
        SUCCESS{
            @Override
             R<Void> payMethod(CommandPayDTO pay,   OrderService orderService) {
              return   orderService.payOk(pay);
            }
        },
        ERROR{
            @Override
             R<Void> payMethod(CommandPayDTO pay,  OrderService orderService) {
               return orderService.payERROR(pay);
            }
        },
        ;
        abstract R<Void> payMethod(CommandPayDTO pay, OrderService orderService);
    }
    @AllArgsConstructor
  public enum StrategyFunction {
        PayOK("1",Strategy.SUCCESS),
        PayERROR("2",Strategy.ERROR);
        ;
        private final String code;
        private  final Strategy strategy;
        private static Map<String,Strategy> map ;
        static {
            map = Arrays.stream(StrategyFunction.values()).collect(Collectors.toMap(item->item.code,item->item.strategy));
        }
        public static R<Void> toDo(CommandPayDTO pay, OrderService orderService){
            return map.get(pay.getPayStatus()).payMethod(pay, orderService);
        }



    }
}
